import java.util.Scanner;

public class HihoCoder1518 {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int N=in.nextInt();
		int[] a=new int[N+1];
		for(int i=1;i<=N;i++){
			a[i]=in.nextInt();
		}
		int max=0;
		for(int i=1;i<=N;i++){
			int entity=GetCount(i,N,a);
			max=max>entity?max:entity;
		}
		System.out.println(max);
	}

	private static int GetCount(int num,int N, int[] a) {
		int size=0;
		boolean[] has = new boolean[N+1];
		int index=a[num];
		while(!has[index]){
			has[index]=true;
			index=a[index];
			size++;
		}
		return size;
	}

}
